package com.example.demo.zhoushengwen.response;

import org.springframework.http.HttpStatus;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@ToString
@NoArgsConstructor
public class ResponseResult implements Response
{
    
    //操作是否成功
    boolean success = SUCCESS;
    
    //操作状态码
    int code = SUCCESS_CODE;
    
    //提示信息
    String message;
    
    //携带数据
    Object data;
    
    public ResponseResult(ResultCode resultCode, Object data)
    {
        this.success = resultCode.success();
        this.code = resultCode.code();
        this.message = resultCode.message();
        this.data = data;
    }
    
    public ResponseResult(ResultCode resultCode)
    {
        this.success = resultCode.success();
        this.code = resultCode.code();
        this.message = resultCode.message();
    }
    
    private ResponseResult(HttpStatus status)
    {
        this.success = false;
        this.code = status.value();
        this.message = status.getReasonPhrase();
    }
    
    public static ResponseResult SUCCESS()
    {
        return new ResponseResult(CommonCode.SUCCESS);
    }
    
    public static ResponseResult FAIL()
    {
        return new ResponseResult(CommonCode.FAIL);
    }
    
    public static ResponseResult FAIL(HttpStatus status)
    {
        return new ResponseResult(status);
    }
    
}
